package cn.myfirefly.moming.common.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.myfirefly.moming.common.dao.DataAuthTypeDao;
import cn.myfirefly.moming.common.entity.MmDataAuthType;
import cn.myfirefly.moming.common.model.DataAuthTypeDto;
import cn.myfirefly.moming.common.model.DataAuthTypeFilterDto;
import cn.myfirefly.core.Const;
import cn.myfirefly.core.model.PageResultDto;
import cn.myfirefly.utils.BeanUtil;

@Service
@Transactional
public class DataAuthTypeService {

	@Autowired
	private DataAuthTypeDao mmDataAuthTypeDao;
	
	@SuppressWarnings("rawtypes")
	public PageResultDto getList(DataAuthTypeFilterDto dto) {
		
		return mmDataAuthTypeDao.getList(dto);
	}
	
	public List<MmDataAuthType> getList() {
		
		return mmDataAuthTypeDao.getList();
	}
	
	public DataAuthTypeDto getMmDataAuthType(Integer id) {
		MmDataAuthType mmDataAuthType = mmDataAuthTypeDao.get(id);
		DataAuthTypeDto mmDataAuthTypeDto = BeanUtil.copyBeans(DataAuthTypeDto.class, mmDataAuthType);
		return mmDataAuthTypeDto;
	}
	
	public String del(Integer id) {
		MmDataAuthType mmDataAuthType = mmDataAuthTypeDao.get(id);
		if (mmDataAuthType == null) {
			return "该信息不存在，请尝试刷新列表后再操作。";
		}
		mmDataAuthTypeDao.del(mmDataAuthType);
		return Const.ResultCode.SUCCESS;
	}
	
	public Integer insert(DataAuthTypeDto dto) {
		MmDataAuthType mmDataAuthType = BeanUtil.copyBeans(MmDataAuthType.class, dto);
		return mmDataAuthTypeDao.save(mmDataAuthType);
	}
	
	public Integer update(DataAuthTypeDto dto) {
		MmDataAuthType mmDataAuthType = mmDataAuthTypeDao.get(dto.getId());
		if (mmDataAuthType == null) {
			return -1;
		}
		BeanUtil.copyBeans(dto, mmDataAuthType);
		return mmDataAuthTypeDao.save(mmDataAuthType);
	}
}
